package com.imooc.order.message;

import com.fasterxml.jackson.core.type.TypeReference;
import com.imooc.order.utils.JsonUtil;
import com.imooc.product.common.ProductInfoOutput;
import com.rabbitmq.tools.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class MqReceiver {

    //1.@RabbitListener(queues = "myqueuse")
    //2.自动创建队列
    @RabbitListener(queuesToDeclare = @Queue("productInfo"))
    public  void process(String message){


        List<ProductInfoOutput> productInfoOutputList =(List<ProductInfoOutput>) JsonUtil.fromJson(message,
                new TypeReference<List<ProductInfoOutput>>(){});
        log.info("从队列【{}】的消息: {}","productInfo",productInfoOutputList);
    }
}
